﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.Navigate
{
    public static class NavigationService
    {

        public static void GoBack()
        {
            PhoneApplicationPageHelp.GetBasePage().GoBack();
            //var frame = Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame;
            //if (frame != null)
            //{
            //    frame.GoBack();
            //}
        }
        /// <summary>
        /// 扩展系统的导航方法
        /// </summary>
        /// <param name="navigateService"></param>
        /// <param name="uri"></param>
        /// <param name="param"></param>
        public static void Navigate(this System.Windows.Navigation.NavigationService navigateService, string uri, object param = null)
        {
            Navigate(uri, param);
        }


        public static void Navigate(string uri, object param)
        {

            //防止导航到同一页面
            if (uri.Contains("?"))
            {
                uri += "&dateTime_now=" + DateTime.Now.ToLongTimeString();
            }
            else
            {
                uri += "?dateTime_now=" + DateTime.Now.ToLongTimeString();
            }
            GBasePage page = PhoneApplicationPageHelp.GetBasePage();
            page.Navigate(uri, param);
        }
    }
}
